import { printUnitNum } from './../adjustingSetting/printUnit';

import {
  setListFn
  // numMap
} from './../../../utils';

// const printUnitList: any = [];

const printUnitTileList: any = []; // 瓦楞 印刷单元

// const synchronizationPrintUnitList: any = []; // 同步标准值 印刷单元确定按钮

const lengFunId = 8;

const lengFunKey = {
  1: 'AB',
  2: 'A',
  3: 'B',
  4: 'E',
  5: 'C',
  6: 'BE',
  7: 'BC',
  8: 'ABE'
};

const addReadLengFunIdObjList: any = {};

for (let index = 0; index < lengFunId; index++) {
  const i = index + 1;
  addReadLengFunIdObjList[i] = [
    'tile' + lengFunKey[i],
    'frontGear' + lengFunKey[i],
    'forward' + lengFunKey[i],
    'retrogressive' + lengFunKey[i],
    'frontPreloading' + lengFunKey[i],
    'crimping' + lengFunKey[i],
    'rearPreloading' + lengFunKey[i],
    'dieCuttingConveyor' + lengFunKey[i],
    'gap' + lengFunKey[i],
    'dieCuttingGap' + lengFunKey[i]
  ];

  for (let ind = 0; ind < printUnitNum; ind++) {
    addReadLengFunIdObjList[i].push(
      `${ind + 1}ColorImprinting${lengFunKey[i]}`
    );
  }
}

const setFunIdObjFn = (obj, key) => {
  let newObj: any = null;

  if (obj) {
    newObj = {};

    for (const i in obj) {
      newObj[i] = `${key}${obj[i]}`;
    }
  }

  return newObj;
};

const setPrintUnitListFn = (list: any = [], key: any = '') => {
  if (list && list.length) {
    const newList: any = [];

    for (const item of list) {
      const {
        labelZh = null,
        labelEn = null,
        labelRu = null,
        readFunId = null,
        readFunIdObj = null,
        confirmFunId = null,
        confirmFunIdObj = null,
        setpointFunId = null,
        setpointFunIdObj = null,
        addFunId = null,
        addFunIdObj = null,
        reduceFunId = null,
        reduceFunIdObj = null,
        readWriteFunId = null,
        readWriteFunIdObj = null,
        setpointLabelZh = '置数',
        setpointLabelEn = 'Value Reset',
        setpointLabelRu = 'Установка чисел'
      } = item;

      newList.push({
        labelZh,
        labelEn,
        labelRu,
        type: 'input',
        list: setListFn([
          {
            inputType: 'read',
            labelZh: '实际值',
            labelEn: 'Actual Value',labelRu: `Фактическое значение`,
            funId: readFunId === null ? null : `${key}${readFunId}`,
            lengFunIdObj:
              readFunIdObj === null ? null : setFunIdObjFn(readFunIdObj, key)
          },
          {
            inputType: 'readWrite',
            labelZh: '设置值',
            labelEn: 'Set Value',
            funId: readWriteFunId === null ? null : `${key}${readWriteFunId}`,
            defaultValGetFunId:
              readWriteFunId === null ? null : `${key}${readWriteFunId}`,
            lengFunIdObj:
              readWriteFunIdObj === null
                ? null
                : setFunIdObjFn(readWriteFunIdObj, key),
            blurChange: true
          },
          {
            inputType: 'btnBool',
            labelZh: setpointLabelZh,
            labelEn: setpointLabelEn,
            labelRu:setpointLabelRu,
            funId: setpointFunId === null ? null : `${key}${setpointFunId}`,
            lengFunIdObj:
              setpointFunIdObj === null
                ? null
                : setFunIdObjFn(setpointFunIdObj, key),
            clickType: 'startAndEnd',
            writeVal: 1,
            clickTime: 1000
          },
          {
            inputType: 'btnBool',
            labelZh: '向后 +',
            labelEn: 'Backward +',labelRu: 'Назад +',
            funId: addFunId === null ? null : `${key}${addFunId}`,
            lengFunIdObj:
              addFunIdObj === null ? null : setFunIdObjFn(addFunIdObj, key),
            clickType: 'startAndEnd',
            writeVal: 1
          },
          {
            inputType: 'btnBool',
            labelZh: '向前 -',
            labelEn: 'Forward -',labelRu: 'Вперед -',
            funId: reduceFunId === null ? null : `${key}${reduceFunId}`,
            lengFunIdObj:
              reduceFunIdObj === null
                ? null
                : setFunIdObjFn(reduceFunIdObj, key),
            clickType: 'startAndEnd',
            writeVal: 1
          },
          {
            inputType: 'btnBool',
            labelZh: '确认',
            labelEn: 'Confirm',
            funId: confirmFunId === null ? null : `${key}${confirmFunId}`,
            clickType: 'startAndEnd',
            writeVal: 1,
            clickTime: 0,
            lengFunIdObj:
              confirmFunIdObj === null
                ? null
                : setFunIdObjFn(confirmFunIdObj, key)
          }
        ])
      });
    }

    return newList;
  }

  return list;
};

for (let i = 0; i < printUnitNum; i++) {
  const key = i + 1;

  // printUnitList.push({
  //   labelZh: `${numMap[key]}色压印`,
  //   readFunId: `${key}ColorPrintingGapGet`,
  //   readWriteFunId: `${key}ColorPrintingGapSet`,
  //   confirmFunId: `${key}ColorPrintingGapSeal`,
  //   setpointFunId: `${key}ColorPrintingGapUpdate`,
  //   addFunId: `${key}ColorPrintingGapAdd`,
  //   reduceFunId: `${key}ColorPrintingGapSub`
  // });

  printUnitTileList.push({
    funId: `${key}ColorPrintingGapSet`,
    inputType: 'readWrite',
    writeValGetLengFunIdObj: {
      1: `${key}ColorImprintingAB`,
      2: `${key}ColorImprintingA`,
      3: `${key}ColorImprintingB`,
      4: `${key}ColorImprintingE`,
      5: `${key}ColorImprintingC`,
      6: `${key}ColorImprintingBE`,
      7: `${key}ColorImprintingBC`,
      8: `${key}ColorImprintingABE`
    }
  });

  // synchronizationPrintUnitList.push({
  //   clickType: 'startAndEnd',
  //   writeVal: 1,
  //   funId: `${key}ColorImprintingBtn`
  // });

  // printUnitList.push({
  //   type: 'common',
  //   labelZh: `印刷${numMap[key]}单元`,
  //   labelEn: `印刷${numMap[key]}单元[[en]]`,
  //   id: `adjustingPrintUnit${key}`,
  //   list: setPrintUnitListFn(unitDetailsList, key)
  // });
}

const unitDetailsList = [
  {
    labelZh: '前挡板',
    labelEn: 'Front Baffle',labelRu: 'Передний упор',
    readFunId: 'frontBaffleGet',
    readWriteFunId: 'frontBaffleSet',
    confirmFunId: 'frontBaffleSeal',
    setpointFunId: 'frontBaffleUpdate',
    addFunId: 'frontBaffleAdd',
    reduceFunId: 'frontBaffleSub'
  },
  {
    labelZh: '前进纸',
    labelEn: 'Forward Paper-feeding',labelRu: 'Передняя подача бумаги',
    readFunId: 'forwardPaperRollerGet',
    readWriteFunId: 'forwardPaperRollerSet',
    confirmFunId: 'forwardPaperRollerSeal',
    setpointFunId: 'forwardPaperRollerUpdate',
    addFunId: 'forwardPaperRollerAdd',
    reduceFunId: 'forwardPaperRollerSub'
  },
  {
    labelZh: '后进纸',
    labelEn: 'Backward Paper-feeding',labelRu: 'Задняя подача бумаги',
    readFunId: 'rearFeedRollerGet',
    readWriteFunId: 'rearFeedRollerSet',
    confirmFunId: 'rearFeedRollerSeal',
    setpointFunId: 'rearFeedRollerUpdate',
    addFunId: 'rearFeedRollerAdd',
    reduceFunId: 'rearFeedRollerSub'
  },
  // ...printUnitList,
  {
    labelZh: '开槽预压',
    labelEn: 'Slotting Pre-pressing',labelRu: 'Просечка и предварительное прессование',
    readFunId: 'slottingPreloadingWheelGapGet',
    readWriteFunId: 'slottingPreloadingWheelGapSet',
    confirmFunId: 'slottingPreloadingWheelGapSeal',
    setpointFunId: 'slottingPreloadingWheelGapUpdate',
    addFunId: 'slottingPreloadingWheelGapAdd',
    reduceFunId: 'slottingPreloadingWheelGapSub'
  },
  {
    labelZh: '开槽压线',
    labelEn: 'Slotting Crimping',labelRu: 'Просечка и рилевка',
    readFunId: 'slottingBiasCrimpingWheelGapGet',
    readWriteFunId: 'slottingBiasCrimpingWheelGapSet',
    confirmFunId: 'slottingBiasCrimpingWheelGapSeal',
    setpointFunId: 'slottingBiasCrimpingWheelGapUpdate',
    addFunId: 'slottingBiasCrimpingWheelGapAdd',
    reduceFunId: 'slottingBiasCrimpingWheelGapSub'
  },
  {
    labelZh: '开槽后预压',
    labelEn: 'Slotting Late Pre-pressing',labelRu: 'Просечка и заднее предварительное прессование',
    readFunId: 'slottingBiasGapBetweenPaperRollersGet',
    readWriteFunId: 'slottingBiasGapBetweenPaperRollersSet',
    confirmFunId: 'slottingBiasGapBetweenPaperRollersSeal',
    setpointFunId: 'slottingBiasGapBetweenPaperRollersUpdate',
    addFunId: 'slottingBiasGapBetweenPaperRollersAdd',
    reduceFunId: 'slottingBiasGapBetweenPaperRollersSub'
  },
  {
    labelZh: '间隙',
    labelEn: 'Clearance',labelRu: 'Зазор',
    readFunId: 'slottingBiasKnifeGapGet',
    readWriteFunId: 'slottingBiasKnifeGapSet',
    confirmFunId: 'slottingBiasKnifeGapSeal',
    setpointFunId: 'slottingBiasKnifeGapUpdate',
    addFunId: 'slottingBiasKnifeGapAdd',
    reduceFunId: 'slottingBiasKnifeGapSub'
  },
  {
    labelZh: '模切输送',
    labelEn: 'Die-cutting Conveying',labelRu: 'Высечка и перенос',
    readFunId: 'dieCuttingGapBetweenPaperRollersGet',
    readWriteFunId: 'dieCuttingGapBetweenPaperRollersSet',
    confirmFunId: 'dieCuttingGapBetweenPaperRollersSeal',
    setpointFunId: 'dieCuttingGapBetweenPaperRollersUpdate',
    addFunId: 'dieCuttingGapBetweenPaperRollersAdd',
    reduceFunId: 'dieCuttingGapBetweenPaperRollersSub'
  }
];

export default [
  {
    labelZh: `偏心`,
    labelEn: `Off-center`,
    labelRu: `Эксцентрический`,
    id: `adjustingEccentric`,
    addReadLengFunIdObj: addReadLengFunIdObjList,
    saveParameters: false,
    // addReadLengFunIdObj:{
    //   1: [
    //     'tileAB',
    //     'frontGearAB',
    //     'forwardAB',
    //     'retrogressiveAB',
    //     '1ColorImprintingAB',
    //     '2ColorImprintingAB',
    //     '3ColorImprintingAB',
    //     '4ColorImprintingAB',
    //     'frontPreloadingAB',
    //     'crimpingAB',
    //     'rearPreloadingAB',
    //     'dieCuttingConveyorAB',
    //     'gapAB',
    //     'dieCuttingGapAB'
    //   ],
    //   2: [
    //     'tileA',
    //     'frontGearA',
    //     'forwardA',
    //     'retrogressiveA',
    //     '1ColorImprintingA',
    //     '2ColorImprintingA',
    //     '3ColorImprintingA',
    //     '4ColorImprintingA',
    //     'frontPreloadingA',
    //     'crimpingA',
    //     'rearPreloadingA',
    //     'dieCuttingConveyorA',
    //     'gapA',
    //     'dieCuttingGapA'
    //   ],
    //   3: [
    //     'tileB',
    //     'frontGearB',
    //     'forwardB',
    //     'retrogressiveB',
    //     '1ColorImprintingB',
    //     '2ColorImprintingB',
    //     '3ColorImprintingB',
    //     '4ColorImprintingB',
    //     'frontPreloadingB',
    //     'crimpingB',
    //     'rearPreloadingB',
    //     'dieCuttingConveyorB',
    //     'gapB',
    //     'dieCuttingGapB'
    //   ],
    //   4: [
    //     'tileE',
    //     'frontGearE',
    //     'forwardE',
    //     'retrogressiveE',
    //     '1ColorImprintingE',
    //     '2ColorImprintingE',
    //     '3ColorImprintingE',
    //     '4ColorImprintingE',
    //     'frontPreloadingE',
    //     'crimpingE',
    //     'rearPreloadingE',
    //     'dieCuttingConveyorE',
    //     'gapE',
    //     'dieCuttingGapE'
    //   ],
    //   5: [
    //     'tileC',
    //     'frontGearC',
    //     'forwardC',
    //     'retrogressiveC',
    //     '1ColorImprintingC',
    //     '2ColorImprintingC',
    //     '3ColorImprintingC',
    //     '4ColorImprintingC',
    //     'frontPreloadingC',
    //     'crimpingC',
    //     'rearPreloadingC',
    //     'dieCuttingConveyorC',
    //     'gapC',
    //     'dieCuttingGapC'
    //   ],
    //   6: [
    //     'tileBE',
    //     'frontGearBE',
    //     'forwardBE',
    //     'retrogressiveBE',
    //     '1ColorImprintingBE',
    //     '2ColorImprintingBE',
    //     '3ColorImprintingBE',
    //     '4ColorImprintingBE',
    //     'frontPreloadingBE',
    //     'crimpingBE',
    //     'rearPreloadingBE',
    //     'dieCuttingConveyorBE',
    //     'gapBE',
    //     'dieCuttingGapBE'
    //   ],
    //   7: [
    //     'tileBC',
    //     'frontGearBC',
    //     'forwardBC',
    //     'retrogressiveBC',
    //     '1ColorImprintingBC',
    //     '2ColorImprintingBC',
    //     '3ColorImprintingBC',
    //     '4ColorImprintingBC',
    //     'frontPreloadingBC',
    //     'crimpingBC',
    //     'rearPreloadingBC',
    //     'dieCuttingConveyorBC',
    //     'gapBC',
    //     'dieCuttingGapBC'
    //   ],
    //   8: [
    //     'tileABE',
    //     'frontGearABE',
    //     'forwardABE',
    //     'retrogressiveABE',
    //     '1ColorImprintingABE',
    //     '2ColorImprintingABE',
    //     '3ColorImprintingABE',
    //     '4ColorImprintingABE',
    //     'frontPreloadingABE',
    //     'crimpingABE',
    //     'rearPreloadingABE',
    //     'dieCuttingConveyorABE',
    //     'gapABE',
    //     'dieCuttingGapABE'
    //   ]
    // },
    list: [
      {
        type: 'btn',
        labelZh: '设置值',
        labelEn: 'Set Value',
        id: null,
        saveParameters: false,
        hiddenTitle: true,
        list: [
          {
            inputType: 'btnOpenModal',
            labelZh: '参数标准配置',
            labelEn: 'Parameter Standard Configuration',
            labelRu: 'Стандартная конфигурация параметров',
            funId: null,
            defaultValGetFunId: null,
            modalType: 'adjustingModal'
          },
          {
            inputType: 'btnOtherOperate',
            labelZh: '同步标准值',
            labelEn: 'Synchronized Standard Value',
            labelRu: 'Стандартное значение синхронизации',
            funId: null,
            defaultValGetFunId: null,
            writeOtherFunIdList: [
              {
                //前档
                funId: 'frontBaffleSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'frontGearAB',
                  2: 'frontGearA',
                  3: 'frontGearB',
                  4: 'frontGearE',
                  5: 'frontGearC',
                  6: 'frontGearBE',
                  7: 'frontGearBC',
                  8: 'frontGearABE'
                }
              },
              {
                //前进
                funId: 'forwardPaperRollerSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'forwardAB',
                  2: 'forwardA',
                  3: 'forwardB',
                  4: 'forwardE',
                  5: 'forwardC',
                  6: 'forwardBE',
                  7: 'forwardBC',
                  8: 'forwardABE'
                }
              },
              {
                //后进
                funId: 'rearFeedRollerSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'retrogressiveAB',
                  2: 'retrogressiveA',
                  3: 'retrogressiveB',
                  4: 'retrogressiveE',
                  5: 'retrogressiveC',
                  6: 'retrogressiveBE',
                  7: 'retrogressiveBC',
                  8: 'retrogressiveABE'
                }
              },
              {
                //开槽预压
                funId: 'slottingPreloadingWheelGapSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'frontPreloadingAB',
                  2: 'frontPreloadingA',
                  3: 'frontPreloadingB',
                  4: 'frontPreloadingE',
                  5: 'frontPreloadingC',
                  6: 'frontPreloadingBE',
                  7: 'frontPreloadingBC',
                  8: 'frontPreloadingABE'
                }
              },
              {
                //开槽压线
                funId: 'slottingBiasCrimpingWheelGapSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'crimpingAB',
                  2: 'crimpingA',
                  3: 'crimpingB',
                  4: 'crimpingE',
                  5: 'crimpingC',
                  6: 'crimpingBE',
                  7: 'crimpingBC',
                  8: 'crimpingABE'
                }
              },
              {
                //开槽后预压
                funId: 'slottingBiasGapBetweenPaperRollersSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'rearPreloadingAB',
                  2: 'rearPreloadingA',
                  3: 'rearPreloadingB',
                  4: 'rearPreloadingE',
                  5: 'rearPreloadingC',
                  6: 'rearPreloadingBE',
                  7: 'rearPreloadingBC',
                  8: 'rearPreloadingABE'
                }
              },
              {
                //开槽间隙
                funId: 'slottingBiasKnifeGapSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'gapAB',
                  2: 'gapA',
                  3: 'gapB',
                  4: 'gapE',
                  5: 'gapC',
                  6: 'gapBE',
                  7: 'gapBC',
                  8: 'gapABE'
                }
              },
              {
                //模切输送
                funId: 'dieCuttingGapBetweenPaperRollersSet',
                inputType: 'readWrite',
                writeValGetLengFunIdObj: {
                  1: 'dieCuttingConveyorAB',
                  2: 'dieCuttingConveyorA',
                  3: 'dieCuttingConveyorB',
                  4: 'dieCuttingConveyorE',
                  5: 'dieCuttingConveyorC',
                  6: 'dieCuttingConveyorBE',
                  7: 'dieCuttingConveyorBC',
                  8: 'dieCuttingConveyorABE'
                }
              },
              ...printUnitTileList
              // {//开槽预压
              //   funId: 'Set',
              //   writeValGetLengFunIdObj: {
              //     1:'AB',
              //     2:'A',
              //     3:'B',
              //     4:'E',
              //     5:'C',
              //     6:'BE',
              //     7:'BC',
              //     8:'ABE'
              //   }
              // },
            ]
          },
          {
            inputType: 'btnOtherOperate',
            labelZh: '一键归位',
            labelEn: 'One-click Homing',
            labelRu: 'Возврат на место в один клик',
            funId: null,
            defaultValGetFunId: null,
            writeOtherFunIdList: [
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'frontGearBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'forwardBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'retrogressiveBtn'
              },
              // ...synchronizationPrintUnitList,
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'frontPreloadingBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'crimpingBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'rearPreloadingBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'gapBtn'
              },
              {
                clickType: 'startAndEnd',
                writeVal: 1,
                funId: 'dieCuttingConveyorBtn'
              }
            ]
          }
        ]
      },
      {
        type: 'settingWrite',
        labelZh: '设置值',
        labelEn: 'Set Value',
        id: null,
        saveParameters: false,
        hiddenTitle: true,
        list: setListFn([
          {
            labelZh: '楞别',
            labelEn: 'Corrugate Type',
            labelRu: 'Гофрированный тип',
            type: 'input',
            list: [
              {
                inputType: 'lengSelect',
                options: [],
                labelZh: '设置值',
                labelEn: 'Set Value',
                funId: 'tileSelect',
                defaultValGetFunId: 'tileSelect'
              }
            ]
          },
          {
            labelZh: '纸厚',
            labelEn: 'Paper Thickness',
            labelRu: 'Толщина бумаги',
            type: 'input',
            list: [
              {
                inputType: 'readWrite',
                labelZh: '设置值',
                labelEn: 'Set Value',
                funId: null,
                defaultValGetFunId: null,
                setValGetFunId: '',
                blurChange: true,
                lengFunIdObj: {
                  1: 'tileAB',
                  2: 'tileA',
                  3: 'tileB',
                  4: 'tileE',
                  5: 'tileC',
                  6: 'tileBE',
                  7: 'tileBC',
                  8: 'tileABE'
                }
              }
            ]
          },
          {
            labelZh: '印版厚度',
            labelEn: 'Printing Plate Thickness',
            labelRu: 'Толщина печатной формы',
            type: 'input',
            list: [
              {
                inputType: 'readWrite',
                labelZh: '设置值',
                labelEn: 'Set Value',
                funId: 'hardboardThickness',
                defaultValGetFunId: 'hardboardThickness',
                blurChange: true
              }
            ]
          }
        ])
      },
      {
        type: 'common',
        labelZh: `参数`,
        labelEn: `参数[[en]]`,
        // rutodo
        hiddenTitle: true,
        isBlock: true,
        list: setPrintUnitListFn(unitDetailsList)
      }
    ]
  }
];
